/*
package com.study.pdf;


import java.io.FileOutputStream;
import java.io.IOException;

import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.forms.PdfAcroForm;

import java.io.File;
import java.io.IOException;
public class PdfItextGenerator {

    public static void main(String[] args) {
      */
/*  Document document = new Document();
        try {
            PdfWriter.getInstance(document, new FileOutputStream("D:\\Demo\\HelloWorld2.pdf"));
            document.open();
            document.add(new Paragraph("Hello World!"));
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }*//*


        String templatePath = "D:\\Demo\\模板.pdf";
        String outputPath = "D:\\Demo\\gen.pdf";

        try (PdfReader reader = new PdfReader(templatePath);
             PdfWriter writer = new PdfWriter(outputPath);
             PdfDocument pdfDoc = new PdfDocument(reader, writer)) {

            PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
            PdfFormField name = form.getField("name");
            System.out.println(name.getValue());

            // 设置表单字段值
            form.getField("name").setValue("zhangsan");

            // 如果有多个字段，重复上面的步骤
            form.getField("Text1").setValue("sss");

            // 不要忘记保存更改
            pdfDoc.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
*/
